package com.sky.mapper;

import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.ReportDto;
import com.sky.entity.Orders;
import com.sky.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

/**
 * @InterfaceName: ReportMapper
 * @Author: YuanDing
 * @Date: 2024/2/9 16:29
 * @Description:
 */

@Mapper
public interface ReportMapper {


    /**
     * 根据条件统计订单总量
     * @param ordersPageQueryDTO
     * @return
     */
    @Select("select count(*) from orders where order_time >= #{beginTime} and order_time <= #{endTime}")
    Integer countOrderByCondition(OrdersPageQueryDTO ordersPageQueryDTO);

    /**
     * 有效订单统计
     * @param ordersPageQueryDTO
     * @return
     */
    @Select("select count(*) from orders where status = 5 and order_time >= #{beginDateTime} and order_time <= #{endDateTime}")
    Integer validOrderCountByCondition(@Param("beginDateTime") LocalDateTime beginDateTime , @Param("endDateTime") LocalDateTime endDateTime);

    /**
     * 根据条件查询
     * @param beginDate
     * @return
     */
    List<Orders> selectOrderByCondition(@Param("beginDateTime") LocalDateTime beginDateTime , @Param("endDateTime") LocalDateTime endDateTime);

    /**
     * 统计某段时间的有效订单数
     * @param beginDateTime
     * @param endDateTime
     * @return
     */
    @Select("select count(*) from orders where status = 5 and order_time >= #{beginDateTime} and order_time <= #{endDateTime}")
    Integer countValidOrderByDay(@Param("beginDateTime") LocalDateTime beginDateTime , @Param("endDateTime") LocalDateTime endDateTime);


    /**
     * 统计某段时间的全部订单数
     * @param beginDateTime
     * @param endDateTime
     * @return
     */
    @Select("select count(*) from orders where order_time >= #{beginDateTime} and order_time <= #{endDateTime}")
    Integer countOrderByDay(@Param("beginDateTime") LocalDateTime beginDateTime , @Param("endDateTime") LocalDateTime endDateTime);


    /**
     * 获取每天的营业额
     * @param atStartOfDay
     * @param atTime
     * @return
     */
    @Select("select sum(amount) from orders where status = 5 and order_time >= #{beginDateTime} and order_time <= #{endDateTime};")
    Integer countTurnoverByDay(@Param("beginDateTime") LocalDateTime beginDateTime , @Param("endDateTime") LocalDateTime endDateTime);

    /**
     * 统计订单Top10
     * @param beginDateTime
     * @param endDateTime
     * @return
     */
    List<GoodsSalesDTO> countDishTop(@Param("beginDateTime") LocalDateTime beginDateTime , @Param("endDateTime") LocalDateTime endDateTime);


}
